package com.juneyaoair.report;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class MenuMain {

    static  List<MenuDto> list=new ArrayList<>();

    public static void main(String[] args) throws IOException {
        StringBuffer josn=new StringBuffer();
        BufferedReader reader = new BufferedReader(new FileReader("e:/123/menu.txt"));//换成你的文件名
        String line = null;
        while((line=reader.readLine())!=null){
            josn.append(line);
        }
       // System.out.println(josn.toString());
        JSONObject object1= JSONObject.parseObject(josn.toString());

        digui(object1);

        System.out.println(list.size());

        ExcelWriter excelWriter= EasyExcel.write("e:/123/caidan.xlsx", MenuDto.class).build();
        WriteSheet sheet = EasyExcel.writerSheet(0, "城市服务").head(MenuDto.class).build();
        excelWriter.write(list,sheet);
        excelWriter.finish();



    }

    static void digui(JSONObject jsonObject){
        JSONArray object= jsonObject.getJSONArray("children");
        if(object.size()>0){
            for(int i=0;i<object.size();i++){
                MenuDto menu=new MenuDto();
               JSONObject o=object.getJSONObject(i);
               if(o.getString("type").equals("0")){
                   menu.setMenuOne(o.getString("name"));
                   list.add(menu);
                   digui(o);
                   //System.out.println(o.getString("name")+",");
               }else if(o.getString("type").equals("1")){
                   menu.setMenuTwo(o.getString("name"));
                   list.add(menu);
                   //System.out.println("---"+o.getString("name")+",");
                   digui(o);
               }else if(o.getString("type").equals("2")){
                   menu.setMenuThree(o.getString("name"));
                   list.add(menu);
                   //System.out.println("---"+o.getString("name")+",");
                  // digui(o);
               }


            }
        }
    }

}
